@echo off

:: TODO: Add error checking (after running each script/exe)

echo Creating output directory...

:: Parse current time

set dt=%date% %time%
set yr=%dt:~12,2%
set mt=%dt:~4,2%
set dy=%dt:~7,2%
set hr=%dt:~15,2%
set mn=%dt:~18,2%
set sc=%dt:~21,2%

:: Fix one digit hours
if %hr% LSS 10 (
  set hr=0%hr:~-1%
)

set ts=%yr%%mt%%dy%_%hr%%mn%%sc%

:: Check python version
set pythonexe=

if exist "C:\python27\ArcGISx6410.2\python.exe" (
  set pythonexe="C:\python27\ArcGISx6410.2\python.exe"
  echo %dt% - Using 64-bit Python. >> %outdir%\Swsp.Build.log
  echo %dt% - Using 64-bit Python.
) else if exist "C:\python27\ArcGIS10.2\python.exe" (
  set pythonexe="C:\python27\ArcGIS10.2\python.exe"
  echo %dt% - Using 32-bit Python. >> %outdir%\Swsp.Build.log
  echo %dt% - Using 32-bit Python.
) else (
  echo "%dt% - Could not find Python executable. Terminating build script." >> %outdir%\Swsp.Build.log
  echo "%dt% - Could not find Python executable. Terminating build script."
  goto END
)

%pythonexe% rawq_publish.py && (
  echo %dt% - rawq_publish.py returned successfully >> Swsp.RawqPublish.log
  echo %dt% - rawq_publish.py returned successfully
) || (
  echo %dt% - rawq_publish.py returned error %errorlevel%. Terminating build script. >> Swsp.RawqPublish.log
  echo %dt% - rawq_publish.py returned error %errorlevel%. Terminating build script.
  goto END
)


:END